﻿
@{
    Layout = null;
}

<div class="panel panel-default" ng-controller="PointOrderManageController" ng-class="{ 'whirl standard': isLoading }">
    <div class="panel-heading">
        <div class="form-inline ng-pristine ng-valid">
            <div class="form-group">
                <input placeholder="订单号" class="form-control" type="text" ng-model="Keywords">
                <select class="form-control" ng-model="OrderStatus">
                    <option value="-1">订单状态</option>
                    <option value="0">待确认</option>
                    <option value="1">已确认</option>
                    <option value="2">已收货</option>
                    <option value="3">已完成</option>
                    <option value="4">已取消</option>
                    <option value="5">已作废</option>
                </select>
                <select class="form-control" ng-model="SendStatus">
                    <option value="-1">发货状态</option>
                    <option value="0">未发货</option>
                    <option value="1">已发货</option>
                    <option value="2">部分发货</option>
                </select>
                <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()">
                    <span class="btn-label">
                        <em class="fa fa-search"></em>
                    </span>搜索
                </button>
            </div>
        </div>
    </div>
    <div class="panel-body">
        <div class="table-responsive">
            <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                <tbody>
                    <tr ng-repeat="agentInfoManage in $data">
                        <td data-header="'checkboxheader.html'" class="text-center">
                            <div class="checkbox c-checkbox">
                                <label>
                                    <input type="checkbox" ng-model="checkboxes.items[$index].isChecked" ng-change="changeChecked()" />
                                    <span class="fa fa-check"></span>
                                </label>
                            </div>
                        </td>
                        <td data-title="'订单号'" class="text-center">{{agentInfoManage.OrderNo}}</td>
                        <td data-title="'收货人'" class="text-center">{{agentInfoManage.ReceiveName}}</td>
                        <td data-title="'手机号'" class="text-center">{{agentInfoManage.ReceivePhone}}</td>
                        <td data-title="'地址'" class="text-center">{{agentInfoManage.ReceiveAddress}}</td>
                        <td data-title="'使用积分'" class="text-center">{{agentInfoManage.UsePoints}}</td>
                        <td data-title="'订单状态'" class="text-center">{{agentInfoManage.OrderStatusDes}}</td>
                        <td data-title="'发货状态'" class="text-center">{{agentInfoManage.SendStatusDes}}</td>
                        <td data-title="'订单时间'" class="text-center">{{agentInfoManage.AddTime}}</td>
                        <td data-title="''" nowrap="nowrap" class="text-center">
                            <button type="button" ng-click="editBasicInfo(agentInfoManage.Id)" class="btn btn-sm btn-info" title="查看">
                                <em class="fa fa-eye"></em>
                            </button>
                            <button type="button" ng-click="delOrder(agentInfoManage.Id)" class="btn btn-sm btn-danger" title="删除">
                                <em class="fa fa-trash-o"></em>
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <script type="text/ng-template" id="checkboxheader.html">
        <div data-toggle="tooltip" class="checkbox c-checkbox">
            <label>
                <input type="checkbox" ng-model="checkboxes.checked" ng-change="checkedAll()" />
                <span class="fa fa-check"></span>
            </label>
        </div>
    </script>

    @*<script type="text/ng-template" id="logDialogId">
            <div class="ngdialog-message">
                <h3>操作日志</h3>
                <span class="text-danger">共查询到{{totalCount}}条记录</span>
                <div class="panel panel-default" ng-class="{ 'whirl standard': isLoadinglog }">
                    <table ng-table="logTableParams" class="table table-striped table-bproducted table-hover">
                        <tr ng-repeat="loginfo in $data">
                            <td class="text-center" data-title="'操作时间'">{{loginfo.AddTime}}</td>
                            <td class="text-center" data-title="'操作人'">{{loginfo.EmployeeName}}</td>
                            <td class="text-center" data-title="'操作类型'">{{convertToEnum(loginfo.OperationType,enumDormMSOperationType)}}</td>
                            <td class="text-center" data-title="'备注'">{{loginfo.Remark}}</td>
                        </tr>
                    </table>
                    <div class="panel-footer text-right">
                        <button type="button" class="btn btn-default" ng-click="closeThisDialog()">
                            关闭
                        </button>
                    </div>
                </div>
            </div>
        </script>*@

    <script>

        App.controller('PointOrderManageController', [
        '$scope', '$resource', '$state', '$route', '$http', 'ngTableParams', 'ngTableDataService', 'Notify', '$rootScope',
        function ($scope, $resource, $state, $route, $http, ngTableParams, ngTableDataService, Notify, $rootScope) {
            'use strict';
            $scope.isLoading = true;
            $scope.OrderStatus = -1;
            $scope.SendStatus = -1;
            $scope.PayStatus = -1;

            $scope.tableParams = new ngTableParams({
                page: 1,
                count: 10,
                sorting: {
                    Id: 'desc'     // 初始化排序
                }
            }, {
                getData: function ($defer, params) {
                    $scope.isLoading = true;
                    var requestParams = {
                        Skip: (params.page() - 1) * params.count(),
                        Take: params.count(),
                        Keywords: $scope.Keywords,
                        OrderStatus: $scope.OrderStatus,
                        SendStatus: $scope.SendStatus,
                        PayStatus: $scope.PayStatus
                    };
                    $http.post('/Order/GetPointOrderList', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                        .success(function (data, status) {
                            params.total(data.Total);
                            $defer.resolve(data.Results);
                            $rootScope.checkboxes = { checked: false, items: [] };
                            angular.forEach(data.Results, function (item) {
                                $rootScope.checkboxes.items.push({
                                    itemNo: item.OrderNo,
                                    isChecked: false
                                });
                            });
                            $scope.isLoading = false;
                        });
                }
            });

            //跳转更新页面
            $scope.editBasicInfo = function (id) {
                $state.go('app.orderInfo', { "id": id });
            }

            $scope.delOrder = function (id) {
                layer.confirm('确定删除吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    layer.closeAll('dialog');
                    $http.post("/Order/DelOrder", { id: id }).then(function (response) {

                        if (response.data.isSuccess) {
                            $scope.tableParams.$params.page = 1;
                            $scope.isLoading = true;
                            $scope.tableParams.reload();
                            $scope.isLoading = false;
                        }
                        else {
                            layer.msg(response.data.msg);
                        }

                    });
                }, function () {

                });
            }
        }
        ]);
    </script>

</div>
